package cn.cas.mango.util.paramCheck;

import cn.cas.mango.dto.param.HotListDetailParam;
import cn.cas.mango.dto.param.SearchHotParam;
import cn.cas.mango.service.ConfigService;
import cn.cas.mango.util.RenderDateUtil;
import cn.cas.mango.util.string.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;

@Service
@Slf4j
public class SearchHotParamCheckUtil {
  @Autowired
  private ConfigService configService;
  public void check(SearchHotParam param) {
    param.setUuid(StringUtils.getUUID());
    if (param.getStartDate() == null) {
      String today = RenderDateUtil.getToday();
      String s = RenderDateUtil.plusNDay(today, -2);
      param.setStartDate(s + " 00:00:00");
    }
    if (param.getEndDate() == null) {
      param.setEndDate(RenderDateUtil.getNow());
    }

    String startDate = param.getStartDate();
    String endDate = param.getEndDate();

    if (!param.getStartDate().contains(" ")) {
      startDate = param.getStartDate() + " 00:00:00";
    }
    if (!param.getEndDate().contains(" ")) {
      endDate = RenderDateUtil.plus1day(param.getEndDate()) + " 00:00:00";
    }
    param.setStartDate(startDate);
    param.setEndDate(endDate);

    if (param.getIfAgg() == null) {
      param.setIfAgg(configService.getDefaultIfAgg());
    }

    if (param.getPageSize() == null) {
      param.setPageSize(configService.getSearchHotPageSize());
    }

    if (param.getPageNo() == null) {
      param.setPageNo(1);
    }
    if (param.getSearchMode() == null) {
      param.setSearchMode(1);
    }

    if (param.getSimWeight() == null) {
      param.setSimWeight(configService.getSimWeight());
    }

    if (param.getLikeDegree() == null) {
      param.setLikeDegree(configService.getLikeDegree());
    }
     }
}
